package eval

import (
	"showen/obj"
)

// SymbolToString converts a symbol to a string
// (symbol->string symbol) procedure
func SymbolToString(args []obj.Object, env *obj.Environment) obj.Object {
	if len(args) != 1 {
		return &Error{Message: "symbol->string requires exactly 1 argument"}
	}

	if args[0].Type() != obj.SYMBOL_OBJ {
		return &Error{Message: "symbol->string argument must be a symbol"}
	}

	symbol := args[0].(*obj.SymbolObject)
	return &obj.StringObject{Value: symbol.Value}
}

// StringToSymbol converts a string to a symbol
// (string->symbol string) procedure
func StringToSymbol(args []obj.Object, env *obj.Environment) obj.Object {
	if len(args) != 1 {
		return &Error{Message: "string->symbol requires exactly 1 argument"}
	}

	if args[0].Type() != obj.STRING_OBJ {
		return &Error{Message: "string->symbol argument must be a string"}
	}

	str := args[0].(*obj.StringObject)
	return &obj.SymbolObject{Value: str.Value}
}